package com.hisysteTopet.hisystepet.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisysteTopet.hisystepet.bean.Foster;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FosterMapper extends BaseMapper<Foster> {

    // 根据用户名查询改用户的所有预约信息
    @Select("SELECT * FROM foster WHERE username = #{username} ORDER BY  foster_id  DESC")
    public List<Foster> selectByUsername(String username);

    // 根据用户名删除改预约信息
    @Delete("DELETE FROM foster WHERE foster_id = #{fosterId}  AND username = #{username}; ")
    public void deleteByFosterId(String fosterId,String username);

    // 根据用户名添加预约信息
    @Insert(" INSERT INTO  foster(username,why,`data`) " +
            "VALUE(#{username},#{why},#{data});")
    public void insertByFosterId(String username,String why,String data);

    // 查询所有待审核的预约信息
    @Select("SELECT * FROM foster WHERE audit = '待审核'")
    public List<Foster> auditAllMessage();

    // 审核通过
    @Update("UPDATE foster SET foster.`audit` = #{audit} ," +
            " foster.`audit_results` = #{auditResults} WHERE foster.`foster_id` = #{fosterId} ")
    public void updateFosterMessageByYes(String audit ,String auditResults, Integer fosterId);

    // 审核不通过
    @Update("UPDATE foster SET foster.`audit` = #{audit} ," +
            " foster.`audit_results` = #{auditResults} WHERE foster.`foster_id` = #{fosterId} ")
    public void updateFosterMessageByNo(String audit ,String auditResults,Integer fosterId);

}

